/////////////////////////////////////////////////////////////////////////////
// WMPHotkeys.cpp : Implementation of CWMPHotkeys
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "WMPHotkeys.h"

//globals
CComPtr<IWMPCore> g_core;
//keyboard hook
HHOOK g_hHook;

/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys::CWMPHotkeys
// Constructor

CWMPHotkeys::CWMPHotkeys()
{
	g_hHook = NULL;
	g_core = NULL;
    wcsncpy_s(m_wszPluginText, sizeof(m_wszPluginText) / sizeof(m_wszPluginText[0]), L"WMP Hotkeys", sizeof(m_wszPluginText) / sizeof(m_wszPluginText[0]));
}

/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys::~CWMPHotkeys
// Destructor

CWMPHotkeys::~CWMPHotkeys()
{
}

/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys:::FinalConstruct
// Called when an plugin is first loaded. Use this function to do one-time
// intializations that could fail instead of doing this in the constructor,
// which cannot return an error.

HRESULT CWMPHotkeys::FinalConstruct()
{
	//set the keyboard hook
	g_hHook = SetWindowsHookEx(WH_KEYBOARD, keyHookProc, NULL, GetCurrentThreadId());
    return S_OK;
}

/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys:::FinalRelease
// Called when a plugin is unloaded. Use this function to free any
// resources allocated in FinalConstruct.

void CWMPHotkeys::FinalRelease()
{
	//de register global windows hook
	if(g_hHook != NULL)
	{
		UnhookWindowsHookEx(g_hHook);
		g_hHook = NULL;
	}
    ReleaseCore();
}

/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys::SetCore
// Set WMP core interface

HRESULT CWMPHotkeys::SetCore(IWMPCore *pCore)
{
    HRESULT hr = S_OK;

    // release any existing WMP core interfaces
    ReleaseCore();

    // If we get passed a NULL core, this  means
    // that the plugin is being shutdown.

    if (pCore == NULL)
    {
        return S_OK;
    }

    m_spCore = pCore;
	g_core = pCore;

    return hr;
}

/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys::ReleaseCore
// Release WMP core interfaces

void CWMPHotkeys::ReleaseCore()
{
    if (m_spCore)
    {
        m_spCore = NULL;
		g_core = NULL;
    }
}


/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys::DisplayPropertyPage
// Display property page for plugin

HRESULT CWMPHotkeys::DisplayPropertyPage(HWND hwndParent)
{
    return S_OK;
}

/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys::GetProperty
// Get plugin property

HRESULT CWMPHotkeys::GetProperty(const WCHAR *pwszName, VARIANT *pvarProperty)
{
    if (NULL == pvarProperty)
    {
        return E_POINTER;
    }

    return E_NOTIMPL;
}

/////////////////////////////////////////////////////////////////////////////
// CWMPHotkeys::SetProperty
// Set plugin property

HRESULT CWMPHotkeys::SetProperty(const WCHAR *pwszName, const VARIANT *pvarProperty)
{
    return E_NOTIMPL;
}
